<?php

$objAjax = new xajax();
$objAjax->processRequests();

$vacancy = $records['vacancy'];
$company = $records['company'];

$langList = $records['lang'];
$skillList = $records['skill'];

if ($records['retrySubmission'] && isset($records['savedData'])) {
	foreach ($records['savedData'] as $varName => $value) {
		$$varName = $value;
	}
}

$formAction = $_SERVER['PHP_SELF'] . '?recruitcode=ApplicantApply';

$iconDir = "../../themes/{$styleSheet}/icons/";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../scripts/archive.js"></script>
<?php
	$objAjax->printJavascript();
?>
<script>
//<![CDATA[

    function goBack() {
        location.href = "<?php echo "{$_SERVER['PHP_SELF']}?recruitcode=ApplicantViewJobs"; ?>";
    }

	function validate() {
		err = false;
		var msg = '<?php echo $lang_Error_PleaseCorrectTheFollowing; ?>\n\n';
		var errors = new Array();

		var fields = new Array("txtFirstName", "txtMiddleName", "txtLastName", "txtStreet1",
						"txtStreet2", "txtCity", "txtCountry", "txtProvince", "txtZip", "txtPhone",
						"txtMobile", "txtEmail", "txtQualifications","txtskill","txtlang","txtexperience");

		var fieldNames = new Array('<?php echo $lang_Recruit_ApplicationForm_FirstName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_MiddleName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_LastName;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Street1;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Street2;?>',
						'<?php echo $lang_Recruit_ApplicationForm_City;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Country;?>',
						'<?php echo $lang_Recruit_ApplicationForm_StateProvince;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Zip;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Phone;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Mobile;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Email;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Qualifications;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Technical_Skill;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Foreign_Languages;?>',
						'<?php echo $lang_Recruit_ApplicationForm_Experiences;?>');

		// compulsary fields
		var compFields = new Array(0, 2, 3,10, 11,13,14,15);
		var emailFields = new Array();
		emailFields[0] = 11;
		var phoneFields = new Array();
		//phoneFields[0] = 9;
		phoneFields[0] = 10;
		
		
		

		// validate compulsary fields
		var numCompFields = compFields.length;
		for (var i = 0; i < numCompFields; i++ ) {
			var fieldNdx = compFields[i];
			var fieldName = fields[fieldNdx];
		    var value = $(fieldName).value.trim();
		    if (value == '') {
				err = true;
				msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecify ?>" + fieldNames[fieldNdx] + "\n";
		    }
		}
		

		//
		// Only check validation if all compulsary fields have been specified
		//
		if (err == false) {

			// validate email fields
			var numEmailFields = emailFields.length;
			for (var i = 0; i < numEmailFields; i++ ) {
				var fieldNdx = emailFields[i];
				var fieldName = fields[fieldNdx];
			    var value = $(fieldName).value.trim();
			    if (!checkEmail(value)) {
					err = true;
					msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecifyValidEmail ?>" + fieldNames[fieldNdx] + "\n";
			    }
			}

			// validate phone fields
			var numPhoneFields = phoneFields.length;
			for (var i = 0; i < numPhoneFields; i++ ) {
				var fieldNdx = phoneFields[i];
				var fieldName = fields[fieldNdx];
			    var field = $(fieldName);
			    if (!checkPhone(field)) {
					err = true;
					msg += "\t- <?php echo $lang_Recruit_ApplicationForm_PleaseSpecifyValidPhone ?>" + fieldNames[fieldNdx] + "\n";
			    }
			}
			
		}

		if (err) {
			alert(msg);
			return false;
		} else {
			return true;
		}
	}

    function save() {

		if (validate()) {
        	$('fromJobApplication').submit();
		} else {
			return false;
		}
    }

	function resetForm() {
		$('fromJobApplication').reset();
	}

	/*
	 * Get list of provinces for the selected country
	 */
	function getProvinceList(country) {
		showLoading();
		xajax_populateStates(country);
	}

	function hideLoading() {
		var status = $('status');
		status.style.display = 'none';
	}

	function showLoading() {
		var status = $('status');
		status.style.display = 'block';
	}
	
	function imposeMaxLength(Object, MaxLen)
	{
  		return (Object.value.length <= MaxLen);
	}

//]]>
</script>

  
    <link href="../../themes/<?php echo $styleSheet;?>/css/style.css" rel="stylesheet" type="text/css"/>
    <!--[if lte IE 6]>
    <link href="../../themes/<?php echo $styleSheet; ?>/css/IE6_style.css" rel="stylesheet" type="text/css"/>
    <![endif]-->
    <!--[if IE]>
    <link href="../../themes/<?php echo $styleSheet; ?>/css/IE_style.css" rel="stylesheet" type="text/css"/>
    <![endif]-->
</head>
<body>
    <div class="formpage3col">
        <div class="navigation">
        	<input type="button" class="backbutton" value="<?php echo $lang_Common_Back;?>"
        		onclick="goBack();"  />
        </div>
        <div id="status" style="float:right;display:none;">
            <image src='<?php echo $iconDir; ?>/loading.gif' width='20' height='20' style="vertical-align: bottom;">
            <?php echo $lang_Commn_PleaseWait;?>
        </div>
        <div class="outerbox">
            <div class="mainHeading">
                <h2><?php echo $lang_Recruit_ApplicationForm_Heading; echo empty($company) ? "({$lang_Recruit_Application_CompanyNameNotSet})" : $company; ?></h2></div>

        <?php $message =  isset($_GET['message']) ? $_GET['message'] : null;
            if (isset($message)) {
                $messageType = CommonFunctions::getCssClassForMessage($message);
                $message = "lang_Common_" . $message;
        ?>
            <div class="messagebar">
                <span class="<?php echo $messageType; ?>"><?php echo (isset($$message)) ? $$message: ""; ?></span>
            </div>
        <?php } ?>

  <form name="fromJobApplication" id="fromJobApplication" method="post" action="<?php echo $formAction;?>" enctype="multipart/form-data">  
  <input type="hidden" id="txtVacancyId" name="txtVacancyId" value="<?php echo $vacancy->getId();?>"/>
  <input type="hidden" id="txtDirectApply" name="txtDirectApply" value="1"/>
  <table border='0'>
  	<tr>
  		<td>
  			<span class="formLabel"><?php echo "Job Title";?></span>
  		</td>
  		<td>
  			<span class="formValue"><?php echo $vacancy->getJobTitle(); ?></span>
  		</td>  		
  	</tr>  	
  	<tr>
  		<td>
  			<span class="formLabel"><?php echo $lang_Recruit_ApplicationForm_Position;?></span>
  		</td>
  		<td>
  			<span class="formValue"><?php echo $vacancy->getJobTitleName(); ?></span>
  		</td>  		
  	</tr>  	
  	<tr>
  		<td>
  			<label for="txtFirstName"><?php echo $lang_Recruit_ApplicationForm_FirstName; ?><span class="required">*</span></label>
  		</td>
  		<td>
  		 <input type="text" id="txtFirstName" name="txtFirstName" tabindex="1" class="formInputText"
        	value="<?php echo (isset($txtFirstName)) ? $txtFirstName : ''; ?>" />
  		</td>
  	</tr>
  	
  	<tr>
	  	<td>
	  		<label for="txtLastName"><?php echo $lang_Recruit_ApplicationForm_LastName; ?><span class="required">*</span></label>
	  	</td>
	  	<td>
	  		  <input type="text" id="txtLastName" name="txtLastName" tabindex="3" class="formInputText"
	        	value="<?php echo (isset($txtLastName)) ? $txtLastName : ''; ?>" />
	  	</td>
  	</tr>
  	<tr>
	  	<td>
	  		<label for="txtMiddleName"><?php echo $lang_Recruit_ApplicationForm_MiddleName; ?></label>
	  	</td>
	  	<td>
	  		  <input type="text" id="txtMiddleName" name="txtMiddleName" tabindex="3" class="formInputText"
	        	value="<?php echo (isset($txtMiddleName)) ? $txtMiddleName : ''; ?>" />
	  	</td>
  	</tr>
  	
  	 <tr>
	  	<td>
	  		<label for="txtMobile"><?php echo $lang_Recruit_ApplicationForm_Mobile; ?><span class="required">*</span></label>
	  	</td>
	  	<td>
	  		 <input type="text" id="txtMobile" name="txtMobile" tabindex="4" class="formInputText"
        	value="<?php echo (isset($txtMobile)) ? $txtMobile : ''; ?>" />
	  	</td>
  	</tr>
  	<tr>
  		<td>
	  		<label for="txtEmail"><?php echo $lang_Recruit_ApplicationForm_Email; ?><span class="required">*</span></label>
	  	</td>
	  	<td>
	  		 <input type="text" id="txtEmail" name="txtEmail" tabindex="5" class="formInputText"
        	value="<?php echo (isset($txtEmail)) ? $txtEmail : ''; ?>" />
	  	</td>
  	</tr>
  	
  	<tr>
	  	<td>
	  		<label for="txtStreet1"><?php echo "Address"; ?><span class="required">*</span></label>
	  	</td>
	  	<td colspan="3" >
	  		   <textarea id="txtStreet1" name="txtStreet1" tabindex="6" rows="2" cols="80" onkeypress="return imposeMaxLength(this,150);" > <?php echo (isset($txtStreet1)) ? $txtStreet1 : ''; ?></textarea>	
	  	</td>
  	</tr>
  
  	 <tr>
	  	<td>
	  		<label for="txtskill"><?php echo "Technical skills"; ?><span class="required">*</span></label>
	  	</td>
	  	<td colspan="3">
	  		<select name="txtskill[]"  id="txtskill" size="3"  multiple="multiple" style="overflow:scroll;width:120px;">
  				<?php foreach($skillList as $skill){ ?>
				<option  value="<?php echo $skill[0]; ?>"><?php echo $skill[1]; ?></option>
				<?php } ?>
		</select> 
	  	</td>
  	</tr>
  	<tr>
	  	<td>
	  		<label for="txtlang"><?php echo "Foreign languages"; ?><span class="required">*</span></label>
	  	</td>
	  	<td colspan="3">
	  		<select name="txtlang[]"  id="txtlang" size="4" multiple="multiple" style="overflow: auto;width:120px;">
  				<?php foreach($langList as $lang){ ?>
				<option value="<?php echo $lang[0]; ?>"><?php echo $lang[1]; ?></option>
				<?php } ?>
		</select> 
	  	</td>
  	</tr>
  	
  	<tr>
	  	<td>
	  		<label for=txtexperience><?php echo "Experiences"; ?><span class="required">*</span></label>
	  	</td>
	  	<td colspan="3">
	  		<select name="txtexperience"  id="txtexperience" size="1" style="overflow: auto;width:120px;">
  				<?php for($j=0;$j<10;$j++){ ?>
				<option value="<?php echo $j; ?>"><?php echo $j." years "; ?></option>
				<?php } ?>
				<option value="<?php echo 10; ?>"><?php echo ">= 10 years "; ?></option>
		</select>
	  	</td>
  	</tr>
  	
  
  	 <tr>
	  	<td>
	  		<label for="txtQualifications"><?php  echo $lang_Recruit_ApplicationForm_Qualifications; ?></label>
	  	</td>
	  	<td colspan="3">
	  		<textarea id="txtQualifications" name="txtQualifications" tabindex="8" rows="7" cols="80" class="formTextArea"
            style="width:450px;" onkeypress="return imposeMaxLength(this,350);" ><?php  echo (isset($txtQualifications)) ? $txtQualifications : ''; ?></textarea>
	  	</td>
  	</tr>
  
  	
  	<tr>
	  	<td>
	  		<label for="txtResume"><?php echo $lang_Recruit_ApplicationForm_Resume; ?></label>
	  	</td>
	  	<td colspan="3">
	  		<input type="file" id="txtResume" name="txtResume" tabindex="9" class="formFileInput"/><br class="clear"/>
        	<div class="formHint" style="padding-left:10px;"><?php echo $lang_Recruit_ApplicationForm_ResumeDescription; ?></div>
        	
	  	</td>
  	</tr>
  	
  </table>
  <div class="formbuttons">
      <input type="button" class="savebutton" id="saveBtn" tabindex="15"
           onclick="save();" 
           value="<?php echo $lang_Common_Save;?>" />
      <input type="button" class="clearbutton" id="resetBtn" tabindex="16"
           onclick="resetForm();" 
           value="<?php echo $lang_Common_Reset;?>" />
 </div>
	</form>
    </div>

    <div class="requirednotice"><?php echo preg_replace('/#star/', '<span class="required">*</span>', $lang_Commn_RequiredFieldMark); ?>.</div>
    
    </div>
</body>
</html>
